//
//  FRPCell.m
//  FuncionalReactivePixels
//
//  Created by kiwik on 15-2-5.
//  Copyright (c) 2015年 Kiwik. All rights reserved.
//

#import "FRPCell.h"
#import "FRPPhotoModel.h"

@interface FRPCell ()

@property (nonatomic, weak) UIImageView *imageView;
//@property (nonatomic, strong) RACDisposable *subscription;

@end

@implementation FRPCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (!self) return nil;
    
    // Configure self
    self.backgroundColor = [UIColor darkGrayColor];
    
    // Configure subivews
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
    imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    
    [self.contentView addSubview:imageView];
    self.imageView = imageView;
    
    RAC(self.imageView,image)=[[RACObserve(self,photoModel.thumbnailData) ignore:nil] map:^(NSData *data) {
        return [UIImage imageWithData:data];
    }];
    
    return self;
}

//-(void)setPhotoModel:(FRPPhotoModel *)photoModel {
//    self.subscription =
//    [[[RACObserve(photoModel, thumbnailData)
//       filter:^BOOL(id value) {
//           return value != nil;
//       }] map:^id(id value) {
//           return [UIImage imageWithData:value];
//       }]
//     setKeyPath:@keypath(self.imageView, image)
//     onObject:self.imageView];
//}

//-(void)prepareForReuse {
//    [super prepareForReuse];
//    [self.subscription dispose], self.subscription = nil;
//}

@end
